<template>
    <div class="books">
        <van-nav-bar
  title="书刊导入"
  left-text="返回"
  left-arrow
  @click-left="onClickLeft"
 
/>
<van-form v-model="bookArr">
    <van-cell-group inset>
  
      
  <van-field  v-model="bookArr.ISBN" label="ISBN" placeholder="请输入书号" />

<van-field>
    <template #button >
      <van-button class="anniu"  type="primary" @click="submit">一键补全图书信息</van-button>
    </template>
</van-field>
  
  <van-field v-model="bookArr.bookname" label="书名" placeholder="请输入书号" />
  <van-field v-model="bookArr.author" label="作者" placeholder="请输入书号" />
  <van-field v-model="bookArr.units" label="册数" placeholder="请输入册数" />
  <van-field v-model="bookArr.price" label="价格" placeholder="请输入价格" />
  <van-field v-model="bookArr.total" label="总数" placeholder="请输入总数" />
  <van-field v-model="bookArr.press" label="出版社" placeholder="请输入出版社" />
  <van-field name="switch" label="是否推荐">
  <template #input>
    <van-switch v-model="bookArr.flag" />
  </template>
</van-field>
<van-field name="uploader" label="封面图片">
  <template #input>
    <van-image v-model="bookArr.img"  :src="bookArr.img"/>
  </template>
</van-field>



  <van-field
    v-model="bookArr.title"
    rows="1"
    autosize
    label="简介"
    type="textarea"
    placeholder="请输入简介"
  />

  

 

</van-cell-group>
</van-form>

    </div>
</template>

<script setup lang="ts">
import {getBookstAPI} from '@/api/goodsApi'
import { useRouter } from 'vue-router';
import {ref,reactive} from "vue"
let $router = useRouter()
let bookArr = reactive({
 ISBN:'',
 bookname:'',
 author:'',
 units:'',
 price:'',
 total:'',
 press:'',
 flag:'',
 img:'',
 title:''
})

function onClickLeft(){
    $router.back()
}
// const loadBookstAPI=()=>{
//         getBookstAPI({}).then(res=>{
           
            
//            bookArr = res.data.data
//         //    console.log(bookArr);
           
            
//         })
// }

// loadBookstAPI()
function submit(){
  console.log(bookArr);
  if(bookArr.ISBN == '111') {
    getBookstAPI({}).then(res=>{
        console.log(res.data.data[0].img );
        bookArr.bookname = res.data.data[0].bookname
        bookArr.author = res.data.data[0].author
        bookArr.units = res.data.data[0].units
        bookArr.price = res.data.data[0].price
        bookArr.total = res.data.data[0].total
        bookArr.press = res.data.data[0].press
        bookArr.flag = res.data.data[0].flag
        bookArr.img = res.data.data[0].img
        bookArr.title = res.data.data[0].title
        
        
    })
  }
  
}
</script>

<style scoped lang="less">
.books{
    width:100%;
    height:100%;
}
.van-nav-bar{
        background-color:#4fc08d

    }
</style>